#/bin/bash 


grepvar="serverMain"

declare -i i=0
#pid=""
#pname=""
for var in $(ps -u $(basename $HOME) | grep $grepvar)
do   
  if [ $[i%4] -eq 0 ]; then
    pid=$var
    #echo $var
  fi 

  if [ $[i%4] -eq 3 ]; then 
    pname=$var
    #echo $var
  fi 

  if [ "$pid" != "" ] && [ "$pname" != "" ]; 
  then 
    #echo $pid $pname
    kill -9 $pid 
    if [ $? -eq 0 ];
    then 
      echo "$pname is stoped"
    else
      echo "$pname not running"
    fi 
  
  fi 
  i+=1
done
